package com.call.project.frame;

import com.call.project.entity.Meeting;
import com.call.project.utils.ConfigUtils;

import javax.swing.*;
import java.util.HashMap;

/**
 Created by IntelliJ IDEA.
 User: wk
 Date: 2017-03-25 下午9:32
 */
public class SettingFrame extends javax.swing.JFrame {

    /**
     * Creates new form SettingFrame
     */
    public SettingFrame() {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setLocationRelativeTo(null);
        setResizable(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        meetingField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        meetingField2 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        meetingField3 = new javax.swing.JTextField();
        meetingField5 = new javax.swing.JTextField();
        meetingField8 = new javax.swing.JTextField();
        meetingField7 = new javax.swing.JTextField();
        meetingField6 = new javax.swing.JTextField();
        meetingField4 = new javax.swing.JTextField();
        cancleBtn = new javax.swing.JButton();
        confirmBtn = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("会议室名称设置");

        jLabel2.setText("1号会议室");

        meetingField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meetingField1ActionPerformed(evt);
            }
        });

        jLabel3.setText("2号会议室");

        meetingField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meetingField2ActionPerformed(evt);
            }
        });

        jLabel4.setText("3号会议室");

        jLabel5.setText("5号会议室");

        jLabel6.setText("7号会议室");

        jLabel7.setText("4号会议室");

        jLabel8.setText("6号会议室");

        jLabel9.setText("8号会议室");

        meetingField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meetingField3ActionPerformed(evt);
            }
        });

        meetingField8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meetingField8ActionPerformed(evt);
            }
        });

        meetingField7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                meetingField7ActionPerformed(evt);
            }
        });

        cancleBtn.setText("关闭");
        cancleBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancleBtnActionPerformed(evt);
            }
        });

        confirmBtn.setText("确定");
        confirmBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup().addGap(251, 251, 251).addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup().addGap(22, 22, 22)
                        .addGroup(
                            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel4)
                                .addComponent(jLabel2).addComponent(jLabel5).addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(meetingField1).addComponent(meetingField3).addComponent(meetingField5)
                            .addComponent(meetingField7, javax.swing.GroupLayout.DEFAULT_SIZE, 180, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup().addGap(38, 38, 38).addComponent(cancleBtn)))
                        .addGap(34,
                            34, 34)
                        .addGroup(
                            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel8)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addComponent(
                                        meetingField6))
                                .addGroup(layout.createSequentialGroup().addComponent(jLabel9)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(meetingField8))
                                .addGroup(layout.createSequentialGroup()
                                    .addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout
                                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addGroup(layout.createSequentialGroup().addComponent(jLabel7)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(meetingField4))
                                            .addGroup(layout.createSequentialGroup().addComponent(jLabel3)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(meetingField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                    180, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                        .addGroup(
                                            layout.createSequentialGroup().addGap(30, 30, 30).addComponent(confirmBtn)))
                                    .addGap(0, 0, Short.MAX_VALUE)))))
                .addGap(22, 22, 22)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addGap(15, 15, 15).addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2)
                    .addComponent(meetingField1, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3).addComponent(meetingField2, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4)
                    .addComponent(jLabel7)
                    .addComponent(meetingField3, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(meetingField4, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(meetingField5, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(meetingField6, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel6)
                    .addComponent(jLabel9)
                    .addComponent(meetingField8, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(meetingField7, javax.swing.GroupLayout.PREFERRED_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(35, 35, 35).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancleBtn).addComponent(confirmBtn))
                .addContainerGap(58, Short.MAX_VALUE)));

        pack();
    }// </editor-fold>                        

    private void meetingField1ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void meetingField2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void meetingField3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void meetingField8ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void meetingField7ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
    }

    private void confirmBtnActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        ConfigUtils.writeMeeting(getSettingList());
        dispose();
    }

    private void cancleBtnActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        dispose();
    }

    public HashMap<Integer, Meeting> getSettingList() {
        HashMap<Integer, Meeting> meetingHashMap = new HashMap<>();
        meetingHashMap.put(1, new Meeting(meetingField1.getText(), 1));
        meetingHashMap.put(2, new Meeting(meetingField2.getText(), 2));
        meetingHashMap.put(3, new Meeting(meetingField3.getText(), 3));
        meetingHashMap.put(4, new Meeting(meetingField4.getText(), 4));
        meetingHashMap.put(5, new Meeting(meetingField5.getText(), 5));
        meetingHashMap.put(6, new Meeting(meetingField6.getText(), 6));
        meetingHashMap.put(7, new Meeting(meetingField7.getText(), 7));
        meetingHashMap.put(8, new Meeting(meetingField8.getText(), 8));
        return meetingHashMap;
    }

    public void setMeeting(HashMap<Integer, Meeting> data) {
        meetingField1.setText(data.get(1).getName());
        meetingField2.setText(data.get(2).getName());
        meetingField3.setText(data.get(3).getName());
        meetingField4.setText(data.get(4).getName());
        meetingField5.setText(data.get(5).getName());
        meetingField6.setText(data.get(6).getName());
        meetingField7.setText(data.get(7).getName());
        meetingField8.setText(data.get(8).getName());
    }

    // Variables declaration - do not modify
    private javax.swing.JButton    cancleBtn;
    private javax.swing.JButton    confirmBtn;
    private javax.swing.JLabel     jLabel1;
    private javax.swing.JLabel     jLabel2;
    private javax.swing.JLabel     jLabel3;
    private javax.swing.JLabel     jLabel4;
    private javax.swing.JLabel     jLabel5;
    private javax.swing.JLabel     jLabel6;
    private javax.swing.JLabel     jLabel7;
    private javax.swing.JLabel     jLabel8;
    private javax.swing.JLabel     jLabel9;
    private javax.swing.JTextField meetingField1;
    private javax.swing.JTextField meetingField2;
    private javax.swing.JTextField meetingField3;
    private javax.swing.JTextField meetingField4;
    private javax.swing.JTextField meetingField5;
    private javax.swing.JTextField meetingField6;
    private javax.swing.JTextField meetingField7;
    private javax.swing.JTextField meetingField8;
    // End of variables declaration                   
}
